﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace gui {

    /// <summary>
    /// Interaction logic for NodeStatsView.xaml
    /// The node properties and stats UI component of the Node Properties Tab
    /// </summary>
    public partial class NodeStatsView : UserControl {
        public NodeStatsView() {
            InitializeComponent();

            AccordianXAML.SelectionMode = AccordionSelectionMode.ZeroOrOne;

            // Set up data binding
            NodeStatsInfo._Dispatcher = this.Dispatcher;
            this.DataContext = NodeStatsInfo.Instance;

            // Register query loading events
            NodeListView.NodeSelectedEvent += DisplayLoadingBar;
            MessageTotalListView.NodeQueryFinishedEvent += HideLoadingBar;
            QueryProgress.Visibility = Visibility.Collapsed;
        }

        // Display the loading bar
        public void DisplayLoadingBar() {
            Random random = new Random();
            int rand = random.Next(40);
            this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                new Action(delegate() {
                QueryProgress.Value = 40 + rand;
                QueryProgress.Visibility = Visibility.Visible;
            }));
        }

        // Hide the loading bar
        public void HideLoadingBar() {
            this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                new Action(delegate() {
                QueryProgress.Visibility = Visibility.Collapsed;
            }));
        }
    }

}
